var uuid;
var pageIndex;
var pageSize;
var searchName = '';
// 获取所有数据和总记录数 { total: 100, data: [...] }
var dataResult = null;

mini.parse();
var grid = mini.get('archivesGrid');

function getArchivesList(pageIndex, pageSize,searchName) {
    $.ajax({
        url: GatewayUrl() + '/archives/list/'+uuid,
        type: 'get',
        async: false,
        data: {
            "pageIndex": pageIndex,
            "pageSize": pageSize,
            "searchName": searchName
        },
        headers: {
            "Authorization": localStorage.getItem("token")
        },
        success: function (dt) {
            console.log(dt);
            if (dt.code === 200) {
                dataResult = mini.decode(dt.data);
            }
        }
    })
}

// 分页填充细节处理
function fillData(pageIndex, pageSize, dataResult, grid) {
    var data = dataResult.data, totalCount = dataResult.total;

    var arr = [];
    var start = pageIndex * pageSize, end = start + pageSize;
    for (var i = 0; i < dataResult.data.length; i++) {
        arr.push(dataResult.data[i]);
    }


    grid.setTotalCount(totalCount);
    grid.setPageIndex(pageIndex);
    grid.setPageSize(pageSize);

    grid.setData(arr);
}

// 监听分页前事件，阻止后自行设置当前数据和分页信息
grid.on("beforeload", function (e) {
    e.cancel = true;
    pageIndex = e.data.pageIndex, pageSize = e.data.pageSize;
    getArchivesList(pageIndex + 1, pageSize,searchName);
    fillData(pageIndex, pageSize, dataResult, grid);
});



////////////////////
//标准方法接口定义
function SetData(data) {
    uuid = data.uuid;
    pageIndex = 0;
    pageSize = 6;
    getArchivesList(pageIndex + 1, pageSize,searchName);
    fillData(0, grid.getPageSize(), dataResult, grid);
}



